// pages/thief-select/index.js
Page({
  data: {
    thieves: [
      {
        id: 1,
        name: "调皮猴子",
        avatar: "/images/avatar-monkey.png",
        mood: "兴奋",
        specialAbility: "快速偷取",
        description: "这只猴子非常机敏，能够快速地偷取心情，适合追求速度的玩家。"
      },
      {
        id: 2,
        name: "机智狐狸",
        avatar: "/images/avatar-fox.png",
        mood: "冷静",
        specialAbility: "隐身术",
        description: "狐狸拥有隐身技能，可以在不被发现的情况下偷取心情，成功率极高。"
      },
      {
        id: 3,
        name: "神秘猫咪",
        avatar: "/images/avatar-cat.png",
        mood: "开心",
        specialAbility: "心灵感应",
        description: "猫咪能够感知目标的情绪波动，选择最佳时机进行偷取，非常神秘。"
      },
      {
        id: 4,
        name: "调皮企鹅",
        avatar: "/images/avatar-penguin.png",
        mood: "愉快",
        specialAbility: "冰冻技能",
        description: "企鹅可以使用冰冻技能减缓目标的反应速度，提高偷取成功率。"
      }
    ],
    partnerInfo: {
      nickName: "女朋友",
      avatarUrl: "/images/friend-1.png"
    },
    // 预定义的心情选项
    moodOptions: [
      { name: '伤心', value: 'sad', emoji: '😢' },
      { name: '焦虑', value: 'anxious', emoji: '😰' },
      { name: '愤怒', value: 'angry', emoji: '😡' },
      { name: '沮丧', value: 'depressed', emoji: '😔' },
      { name: '疲惫', value: 'tired', emoji: '😫' }
    ],
    selectedThief: null
  },

  onLoad: function (options) {
    // 页面加载时的初始化逻辑
    console.log('心情小偷页面加载');
  },

  onReady: function () {
    // 页面渲染完成
  },

  onShow: function () {
    // 页面显示
  },

  onHide: function () {
    // 页面隐藏
  },

  onUnload: function () {
    // 页面关闭
  },

  // 选择小偷
  selectThief(e) {
    const thief = e.detail;
    
    this.setData({
      selectedThief: thief
    });
    
    // 选择小偷后直接进入下一步
    this.chooseMood();
  },

  // 取消选择
  cancelSelection() {
    this.setData({
      selectedThief: null
    });
  },

  // 选择要偷取的心情
  chooseMood() {
    const moodItems = this.data.moodOptions.map(option => `${option.emoji} ${option.name}`);
    
    wx.showActionSheet({
      itemList: moodItems,
      success: (res) => {
        const selectedMood = this.data.moodOptions[res.tapIndex];
        this.startStealProcess(selectedMood);
      },
      fail: () => {
        // 用户取消选择，取消小偷选择
        this.setData({
          selectedThief: null
        });
      }
    });
  },

  // 开始偷取流程
  startStealProcess(mood) {
    const duration = 30 * 60 * 1000; // 30分钟
    const startTime = Date.now();
    const endTime = startTime + duration;
    
    const stealData = {
      thief: this.data.selectedThief,
      targetMood: mood,
      startTime,
      endTime,
      duration
    };
    
    // 保存到本地存储
    wx.setStorageSync('active_steal', stealData);
    
    // 跳转到偷取页面
    wx.navigateTo({
      url: `/pages/thief/steal/index?stealData=${encodeURIComponent(JSON.stringify(stealData))}`
    });
  },
})